﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace CoilIntelStorage.Utils
{
    /// <summary>
    /// 克隆工具类
    /// </summary>
    public static class ObjectCloneUtil
    {
        /// <summary>
        /// 使用序列化的方法实现深克隆
        /// </summary>
        /// <typeparam name="T">被克隆的类型</typeparam>
        /// <param name="source">被克隆的对象</param>
        /// <param name="destination">克隆返回的对象</param>
        public static void Clone<T>(T source, ref T destination) where T : class
        {
            string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(source);
            destination = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsonStr);
        }
    }
}
